import java.util.*;

/**
 * Created by qtbui on 2017/9/21.
 */

class TreeNode
{
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}

class Solution
{
	public int maxDepth(TreeNode root)
	{
		return getMaxDepth(root,1);
	}

	public int getMaxDepth(TreeNode tn, int level)
	{
		if(tn==null)
		{
			return level-1;
		}

		int leftLevel=getMaxDepth(tn.left,level+1);
		int rightLevel=getMaxDepth(tn.right,level+1);

		return Max(leftLevel,rightLevel,level);
	}

	private int Max(int a,int b,int c)
	{
		int x=Math.max(a,b);
		return Math.max(x,c);
	}
}

public class test
{
    public static void main(String[] args)
    {
		TreeNode tn=new TreeNode(0);
		tn.left=new TreeNode(1);
		tn.right=new TreeNode(1);
		tn.left.left=new TreeNode(2);
		tn.left.right=new TreeNode(3);
		tn.right.left=new TreeNode(3);
		tn.right.right=new TreeNode(2);

		System.out.println(new Solution().maxDepth(tn));
    }
}
